package com.zygh.questionnairesurvey.controller;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.zygh.questionnairesurvey.common.CommonResult;
import com.zygh.questionnairesurvey.entity.Questionnaire;
import com.zygh.questionnairesurvey.server.QuestionnaireService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/Questionnaire")
@Api(tags = "调查问卷")
public class QuestionnaireController {

    @Resource
    private QuestionnaireService questionnaireService;


    @GetMapping("getById")
    @ApiOperation(value = "根据警号查询")
    public CommonResult getById(String username) {
        return questionnaireService.getById(username);
    }

    @PostMapping("insert")
    @ApiOperation(value = "新增调查问卷")
    public CommonResult insert(@RequestBody Questionnaire questionnaire) {
        return questionnaireService.insert(questionnaire);
    }


    @PostMapping("update")
    @ApiOperation(value = "修改调查问卷")
    public CommonResult update(@RequestBody Questionnaire questionnaire) {
        return questionnaireService.update(questionnaire);
    }


    @PostMapping("delete")
    @ApiOperation(value = "删除调查问卷")
    public CommonResult delete(@RequestBody String id) {
        String str = JSONObject.parseObject(id).get("id").toString();
        Integer new_id = Integer.parseInt(str);
        return questionnaireService.delete(new_id);
    }

    @GetMapping("findProblemInfoById")
    @ApiOperation(value = "民警问题统计")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "部门id", dataType = "Integer"),
    })
    public CommonResult findProblemInfoById(Integer id) {
        return questionnaireService.findProblemInfoById(id);
    }

    @GetMapping("findWorker")
    @ApiOperation(value = "工勤人员问题统计")
    public CommonResult findWorker(Integer id) {
        return questionnaireService.findWorker(id);
    }


    @GetMapping("findProblemAll")
    @ApiOperation(value = "全部警员问题统计")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "部门id", dataType = "Integer"),
    })
    public CommonResult findProblemAll(Integer id) {
        return questionnaireService.findProblemAll(id);
    }



    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ApiOperation(value = "通过问题id和大队id分页查询具体人员")
    public Object list(@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                       @RequestParam(value = "pageSize", defaultValue = "10") int pageSize,
                       @ApiParam(name = "deptId", value = "部门id")
                       @RequestParam(required = false) Integer deptId,
                       @ApiParam(name = "lowest", value = "问题id", required = true)
                       @RequestParam Integer lowest,
                       @ApiParam(name = "termStatus", value = "不为3：民警、领导班子   3：工勤人员）")
                       @RequestParam(required = false) Integer termStatus) {
        PageInfo list = questionnaireService.list(pageNum, pageSize, deptId, lowest, termStatus);

        return new CommonResult().success(list);
    }


    @GetMapping("test")
    public void test(){
        questionnaireService.test();
    }
}